package com.xuelang.pipeline.worker.entry.util;

import io.kubernetes.client.openapi.models.V1PodCondition;
import org.apache.commons.collections4.CollectionUtils;

import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author liuyuan.ly
 * @since 2024/5/29 11:45
 */
public class Utils {


    public static String OffsetDateTime2Str(OffsetDateTime startTime) {
        if (null == startTime) {
            return "";
        }
        //默认零时区，手动转换成东8区
        return startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.of("+8")));
    }

    public static String getPodReadyStatus(List<V1PodCondition> conditions) {
        String result = "";
        if (CollectionUtils.isEmpty(conditions)) {
            return result;
        }
        for (V1PodCondition condition : conditions) {
            if ("Ready".equals(condition.getType())) {
                return condition.getStatus();

            }
        }
        return result;
    }
}
